﻿package com.evidencer.java.net;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.UnknownHostException;

public class TCPClient {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws UnknownHostException 
	 */
	public static void main(String[] args) throws UnknownHostException, IOException {
		
		// 建立Socket连接
		Socket s=new Socket("127.0.0.1",10000);
		// 获得socket输出流对象
		BufferedWriter bwOut=new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
		
		// 向Socket写入字符串对象
		bwOut.write("Here I Come！");
		bwOut.newLine();
		// 刷新输出流
		bwOut.flush();
		
		// 获得socket输入流对象
		BufferedReader brIn=new BufferedReader(new InputStreamReader(s.getInputStream()));
		// 读取服务器端的响应信息
		String line="";
		if((line=brIn.readLine())!=null){
			System.out.println(line);
		}
		// 关闭当次socket连接
		s.close();
		

	}

}
